import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_admin/api/odoo/sale_pigtail_product_plan_odoo_api.dart';
import 'package:flutter_admin/models/odoo/sale_pigtail_product_plan.dart';
import 'package:flutter_admin/pages/common/cry/cry_button.dart';
import 'package:flutter_admin/pages/common/cry/form/cry_input.dart';
import 'package:flutter_admin/pages/common/cry/form/cry_select_date.dart';
import 'package:flutter_admin/pages/common/cry/model/response_body_api.dart';
import 'package:flutter_admin/pages/common/cry/utils/cry_utils.dart';
import 'package:flutter_admin/pages/common/cry/vo/select_option_vo.dart';
import '../../../generated/l10n.dart';

class SalePigtailProductPlanEdit extends StatefulWidget {
  SalePigtailProductPlanEdit({this.salePigtailProductPlan});

  final SalePigtailProductPlan? salePigtailProductPlan;

  @override
  _SalePigtailProductPlanEditState createState() => _SalePigtailProductPlanEditState();
}

class _SalePigtailProductPlanEditState extends State<SalePigtailProductPlanEdit> {
  late SalePigtailProductPlan salePigtailProductPlan;
  bool? isAdd;

  final GlobalKey<FormState> formKey = GlobalKey<FormState>();

  //late List<SelectOptionVO> activeList;


  @override
  void initState() {
    super.initState();
    this.isAdd = widget.salePigtailProductPlan == null;
    this.salePigtailProductPlan = widget.salePigtailProductPlan ?? SalePigtailProductPlan();
    _loadSelectVO();
  }

   _loadSelectVO() async{
    //activeList=[SelectOptionVO(value:'0',label: "禁用"),SelectOptionVO(value:'1',label: "启用")];
    setState(() { });
  }

  @override
  Widget build(BuildContext context) {
    var form = Form(
      key: formKey,
      child: Wrap(
        children: <Widget>[
          CryInput(
            label: '生产通知单号',
            value: salePigtailProductPlan.orderNumber,
            onSaved: (v) {
              salePigtailProductPlan.orderNumber = v;
            },
          ),

          CryInput(
            label: '客户',
            value: salePigtailProductPlan.clientele,
            onSaved: (v) {
              salePigtailProductPlan.clientele = v;
            },
          ),

          CryInput(
            label: '省份',
            value: salePigtailProductPlan.province,
            onSaved: (v) {
              salePigtailProductPlan.province = v;
            },
          ),

          CryInput(
            label: '系统',
            value: salePigtailProductPlan.economy,
            onSaved: (v) {
              salePigtailProductPlan.economy = v;
            },
          ),

          CryInput(
            label: '地市',
            value: salePigtailProductPlan.city,
            onSaved: (v) {
              salePigtailProductPlan.city = v;
            },
          ),

          CryInput(
            label: '收货人',
            value: salePigtailProductPlan.consignee,
            onSaved: (v) {
              salePigtailProductPlan.consignee = v;
            },
          ),

          CryInput(
            label: '产品名称',
            value: salePigtailProductPlan.productName,
            onSaved: (v) {
              salePigtailProductPlan.productName = v;
            },
          ),

          CryInput(
            label: '型号',
            value: salePigtailProductPlan.pattern,
            onSaved: (v) {
              salePigtailProductPlan.pattern = v;
            },
          ),

          CryInput(
            label: '单位',
            value: salePigtailProductPlan.unit,
            onSaved: (v) {
              salePigtailProductPlan.unit = v;
            },
          ),

          CryInput(
            label: '数量',
            value: salePigtailProductPlan.quantity,
            onSaved: (v) {
              salePigtailProductPlan.quantity = v;
            },
          ),

          CryInput(
            label: '单价',
            value: salePigtailProductPlan.unitPrice,
            onSaved: (v) {
              salePigtailProductPlan.unitPrice = v;
            },
          ),

          CryInput(
            label: '缆径',
            value: salePigtailProductPlan.cableDiameter,
            onSaved: (v) {
              salePigtailProductPlan.cableDiameter = v;
            },
          ),

          CryInput(
            label: '单位芯数',
            value: salePigtailProductPlan.unitCoreNumber,
            onSaved: (v) {
              salePigtailProductPlan.unitCoreNumber = v;
            },
          ),

          CryInput(
            label: '芯数',
            value: salePigtailProductPlan.coreNumber,
            onSaved: (v) {
              salePigtailProductPlan.coreNumber = v;
            },
          ),

          CryInput(
            label: '连接器1',
            value: salePigtailProductPlan.connector1,
            onSaved: (v) {
              salePigtailProductPlan.connector1 = v;
            },
          ),

          CryInput(
            label: '连接器2',
            value: salePigtailProductPlan.connector2,
            onSaved: (v) {
              salePigtailProductPlan.connector2 = v;
            },
          ),

          CryInput(
            label: '米数',
            value: salePigtailProductPlan.meters,
            onSaved: (v) {
              salePigtailProductPlan.meters = v;
            },
          ),

          CryInput(
            label: '总芯数',
            value: salePigtailProductPlan.totalCoreNumber,
            onSaved: (v) {
              salePigtailProductPlan.totalCoreNumber = v;
            },
          ),

          CryInput(
            label: '总行数',
            value: salePigtailProductPlan.totalRows,
            onSaved: (v) {
              salePigtailProductPlan.totalRows = v;
            },
          ),

          CryInput(
            label: '班组',
            value: salePigtailProductPlan.teamMoved0,
            onSaved: (v) {
              salePigtailProductPlan.teamMoved0 = v;
            },
          ),

          CryInput(
            label: '备注',
            value: salePigtailProductPlan.remark,
            onSaved: (v) {
              salePigtailProductPlan.remark = v;
            },
          ),

          CryInput(
            label: '物流停运时间',
            value: salePigtailProductPlan.logisticsDowntime,
            onSaved: (v) {
              salePigtailProductPlan.logisticsDowntime = v;
            },
          ),

          CryInput(
            label: '箱体需求时间',
            value: salePigtailProductPlan.boxDemandTime,
            onSaved: (v) {
              salePigtailProductPlan.boxDemandTime = v;
            },
          ),

          CryInput(
            label: 'create_uid',
            value: salePigtailProductPlan.createUid,
            onSaved: (v) {
              salePigtailProductPlan.createUid = v;
            },
          ),

          CryInput(
            label: 'write_uid',
            value: salePigtailProductPlan.writeUid,
            onSaved: (v) {
              salePigtailProductPlan.writeUid = v;
            },
          ),

           CrySelectDate(
            context,
            label: 'write_date',
            value: salePigtailProductPlan.writeDate,
            onSaved: (v) {
              salePigtailProductPlan.writeDate = v;
            },
          ),

           CrySelectDate(
            context,
            label: '入库时间',
            value: salePigtailProductPlan.warehousingTime,
            onSaved: (v) {
              salePigtailProductPlan.warehousingTime = v;
            },
          ),

          CryInput(
            label: '班组',
            value: salePigtailProductPlan.team,
            onSaved: (v) {
              salePigtailProductPlan.team = v;
            },
          ),

          CryInput(
            label: '产品编码',
            value: salePigtailProductPlan.productSpec,
            onSaved: (v) {
              salePigtailProductPlan.productSpec = v;
            },
          ),

          CryInput(
            label: '车间名称',
            value: salePigtailProductPlan.workshopName,
            onSaved: (v) {
              salePigtailProductPlan.workshopName = v;
            },
          ),

          CryInput(
            label: '车间编码',
            value: salePigtailProductPlan.workshop,
            onSaved: (v) {
              salePigtailProductPlan.workshop = v;
            },
          ),

          CryInput(
            label: '产品',
            value: salePigtailProductPlan.productId,
            onSaved: (v) {
              salePigtailProductPlan.productId = v;
            },
          ),

        ],
      ),
    );
    var buttonBar = ButtonBar(
      alignment: MainAxisAlignment.center,
      children: <Widget>[
        CryButton(
          label: S.of(context).save,
          onPressed: () {
            FormState form = formKey.currentState!;
            if (!form.validate()) {
              return;
            }
            form.save();
            SalePigtailProductPlanOdooApi.saveOrUpdate(salePigtailProductPlan.toOdooMap()).then((ResponseBodyApi res) {
              if (!res.success!) {
               //package:flutter_admin/pages/common/cry(re s.message!);
                return;
              }
              Navigator.pop(context, true);
              CryUtils.message(S.of(context).saved);
            });
          },
          iconData: Icons.save,
        ),
        CryButton(
          label: S.of(context).cancel,
          onPressed: () {
            Navigator.pop(context);
          },
          iconData: Icons.cancel,
        )
      ],
    );
    var result = Scaffold(
      appBar: AppBar(
        title: Text(this.isAdd! ? S.of(context).add : S.of(context).modify),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [form],
        ),
      ),
      bottomNavigationBar: buttonBar,
    );
    return SizedBox(
      width: 650,
      height: 650,
      child: result,
    );
    // return result;
  }
}